//
//  KZLetterCardView.m
//  听说弱点强化训练
//
//  Created by 朱凯 on 2018/10/24.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "KZLetterCardView.h"

@implementation KZLetterCardView
{
    UIImageView *_cardBgView;
    UIImageView *_cardFgView;
    
    UILabel *_letterLabel;
    
}

- (instancetype)init {
    
    if (self = [super init]) {
        
        self.userInteractionEnabled = false;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    _cardBgView = [UIImageView new];
    _cardBgView.image = [UIImage imageNamed:@"kz-卡片背面"];
    [self addSubview:_cardBgView];
    [_cardBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    _cardFgView = [UIImageView new];
    _cardFgView.hidden = true;
    _cardFgView.image = [UIImage imageNamed:@"kz-卡片正面"];
    [self addSubview:_cardFgView];
    [_cardFgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];

    
    _letterLabel = [[UILabel alloc] init];
    _letterLabel.adjustsFontSizeToFitWidth = true;
    _letterLabel.numberOfLines = 1;
    _letterLabel.text = @"";
    _letterLabel.font = FONT(W(60));
    _letterLabel.textAlignment = NSTextAlignmentCenter;
    _letterLabel.textColor = KZThemeColor;
    [_cardFgView addSubview:_letterLabel];
    [_letterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(_cardFgView).multipliedBy(0.8);
        make.center.equalTo(_cardFgView);
    }];
}
- (void)flip:(NSString *)str {
    _letterLabel.text = str;
    self.userInteractionEnabled = true;
    [UIView transitionWithView:self duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        
        _cardBgView.hidden = true;
        _cardFgView.hidden = false;
        

    } completion:^(BOOL finished) {
        
    }];
    [UIView animateWithDuration:0.2 animations:^{
        // 阴影
        self.layer.cornerRadius = 20;
        self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
        self.layer.shadowOffset = CGSizeMake(0, 2);
        self.layer.shadowRadius = 15;
        self.layer.shadowOpacity = 0.6;
        self.layer.shadowColor= UIColor.lightGrayColor.CGColor;
    }];
}


@end
